using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Viettel.VOFFICE.DAO.Models.Mapping
{
    public class AttachmentMap : EntityTypeConfiguration<Attachment>
    {
        public AttachmentMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.FileName)
                .IsRequired()
                .HasMaxLength(256);

            this.Property(t => t.FilePath)
                .IsRequired()
                .HasMaxLength(256);

            this.Property(t => t.DocPath)
                .HasMaxLength(256);

            this.Property(t => t.PdfPath)
                .HasMaxLength(256);

            this.Property(t => t.ImgPath)
                .HasMaxLength(256);

            this.Property(t => t.HtmlPath)
                .HasMaxLength(256);

            // Table & Column Mappings
            this.ToTable("Attachments");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ObjectId).HasColumnName("ObjectId");
            this.Property(t => t.ObjectType).HasColumnName("ObjectType");
            this.Property(t => t.FileName).HasColumnName("FileName");
            this.Property(t => t.FilePath).HasColumnName("FilePath");
            this.Property(t => t.DocPath).HasColumnName("DocPath");
            this.Property(t => t.PdfPath).HasColumnName("PdfPath");
            this.Property(t => t.ImgPath).HasColumnName("ImgPath");
            this.Property(t => t.HtmlPath).HasColumnName("HtmlPath");
            this.Property(t => t.CreatedAt).HasColumnName("CreatedAt");
            this.Property(t => t.UpdatedAt).HasColumnName("UpdatedAt");
            this.Property(t => t.IsDeleted).HasColumnName("IsDeleted");
            this.Property(t => t.DeletedById).HasColumnName("DeletedById");
            this.Property(t => t.CreatorId).HasColumnName("CreatorId");

            // Relationships
            this.HasRequired(t => t.DocumentInbox)
                .WithMany(t => t.Attachments)
                .HasForeignKey(d => d.ObjectId);

        }
    }
}
